package com.ljy.my_study.leetcode.IPO;

import java.util.PriorityQueue;

/**
 * @author: li.junying
 * @create: 2022-03-18 10:13
 */
public class TestMain2 {

    public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {
        int len=profits.length;
        boolean[] visited=new boolean[len];
        PriorityQueue<Integer> queue=new PriorityQueue<>((a,b)->profits[b]-profits[a]);
        for(int j=0;j<k;j++){
            for(int i=0;i<len;i++){
                if(w>=capital[i]&&!visited[i]){
                    queue.offer(i);
                    visited[i]=true;
                }
            }
            if(!queue.isEmpty()){
                int index=queue.poll();
                w+=profits[index];
            }
        }
        return w;
    }

    public static void main(String[] args) {
        int k = 2, w = 0;
        int[] profits = {1,2,3}, capital = {0,1,1};
        System.out.println(new TestMain2().findMaximizedCapital(k,w,profits,capital));
    }
}
